package com.example.covid19.controller;


import cn.hutool.json.JSONUtil;
import com.example.covid19.common.lang.Result;
import com.example.covid19.entity.mongodb.Location;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author BaiZhengChun
 * @since 2023-03-30
 */
@RestController
@RequestMapping("/locationn")
public class LocationnController {
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     *
     * @return从MongoDb里查询经纬度数据
     */
    @RequestMapping("mongsele")
    public Result mongsele(){
        List<Location> local1 = mongoTemplate.find(new Query(Criteria.where("_id").is("64251ae9517b000001002ce8")), Location.class);
        System.out.println(local1);
        return Result.success(200, "ds", mongoTemplate.findAll(Location.class));
    }
    @RequestMapping("insert")
    public void insert(){
        Location location = new Location();
        String[] strArr = new String[]{
                "124.37553,40.18385", "124.37433,40.18520", "124.36995,40.18449", "124.36912,40.18495",
                "124.36794,40.18415", "124.36740,40.18452", "124.36641,40.18449", "124.36643,40.18384",
                "124.36679,40.18378", "124.36673,40.18242", "124.36797,40.18179", "124.36897,40.18197",
                "124.36948,40.18163"
        };
        location.setGver(JSONUtil.toJsonStr(strArr));
        mongoTemplate.save(location);

    }
}
